<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加审批流程' : '修改审批流程' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules">
					<a-form-model-item label="组织类型" prop="ClubTypeID">
						<a-select :allowClear="true" v-model="form.ClubTypeID" placeholder="全部"
							optionFilterProp="children" showSearch>
							<a-select-option v-for="(item, index) in TypeIDList" :key="index" :value="item.ID">
								{{ item.Name }}</a-select-option>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="组织" prop="ClubID">
						<a-select :allowClear="true" v-model="form.ClubID" placeholder="全部"
							optionFilterProp="children" showSearch>
							<a-select-option v-for="(item, index) in clubData" :key="index" :value="item.ID">
								{{ item.Name }}</a-select-option>
						</a-select>
					</a-form-model-item>
					<!-- <a-form-model-item label="组织年审" prop="ClubAnnualAuditID">
						<a-select :allowClear="true" v-model="form.ClubAnnualAuditID" placeholder="全部"
							optionFilterProp="children" showSearch>
							<a-select-option v-for="(item, index) in clubAnnualAuditData" :key="index" :value="item.ID">
								{{ item.Name }}</a-select-option>
						</a-select>
					</a-form-model-item> -->

					<a-form-model-item label="审批节点" prop="ClubAnnualAduitFlowTypeID">
						<a-select v-model="form.ClubAnnualAduitFlowTypeID" show-search :filter-option="filterOption"
							option-filter-prop="children" :autoClearSearchValue="false">
							<template v-for="(item, index) in ActivityFlowTypeList">
								<a-select-option :key="item.ID">{{ item.Name }}</a-select-option>
							</template>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">
							{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}
						</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		ManageApplyClubAnnualAuditFlowDoAdd,
		UpdateApplyActivityFlow,
		CommonDoGetClubAnnualAuditFlowTypeList
	} from '@/api/follow';
	export default {
		props: {
			text: Object,
			clubAnnualAuditData: Array,
			clubData: Array,
			TypeIDList: Array,
		},
		watch: {
			text: function(text) {
				if (JSON.stringify(text) == '{}') {
					
				} else {
					this.form = text;
				}
			}
		},
		data() {
			return {
				ActivityFlowTypeList: [],
				PracticeTeamData: this.global.PracticeTeamData,
				replaceFields: {
					children: 'children',
					title: 'title',
					key: 'ID',
					value: 'ID'
				},
				formLayout: 'horizontal',
				form: this.$form.createForm(this, {
					name: 'coordinated'
				}),
				DepartmenDropdowntList: [],
				form: {
					ClubTypeID: '',
					ClubID:'',
					ClubAnnualAuditID:'',
					ClubAnnualAduitFlowTypeID:''

				},
				rules: {

					ClubAnnualAduitFlowTypeID: [{
						required: true,
						message: '请选择审批节点',
						trigger: 'change'
					}],
					Type: [{
						required: true,
						message: '请选择类型',
						trigger: 'change'
					}]
				}
			};
		},
		activated() {
			this.getOtherList()
		},
		methods: {
			async getOtherList(e) {
				let res = await CommonDoGetClubAnnualAuditFlowTypeList({
					type: e
				});
				this.ActivityFlowTypeList = res.data.data;
			},
			filterOption(input, option) {
				return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
			},
			selectChangetree(e) {
				console.log(e);
				this.form.activityTypeID = e
			},
			closeFunction(data) {
				this.$emit('closeFun', data);
				this.form = {};
			},
			handleSubmit(e) {
				console.log(this.form);
				this.$refs.ruleForm.validate(async valid => {
					if (valid) {
						let data = this.form;
						let res = {};
						data.ClubAnnualAuditID=this.$route.query.clubAnnualAuditID||''
						// console.log(data);
						// return;
						// data.sessionID = this.$route.query.SessionID || ''
						// if(data.ClubTypeID==''&&data.ClubID==''){
						// 	this.$message.error('组织和组织类型必须二选一');
						// 	return
						// }
						if (JSON.stringify(this.text) == '{}') {
							res = await ManageApplyClubAnnualAuditFlowDoAdd(data);
						} else {
							res = await UpdateApplyActivityFlow(data);
						}
						if (res.data.code === 0) {
							this.$message.success(res.data.msg);
							this.closeFunction('1');
						} else {
							this.$message.error(res.data.msg);
						}
					} else {
						return false;
					}
				});
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form-item {
		margin: 20px 50px;
		display: flex;
	}

	/deep/.ant-form-item-label {
		width: 120px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	.ant-form-item {
		margin-bottom: 10px;
	}

	/deep/.ant-form {
		margin-top: 50px;
		padding-bottom: 50px;
	}
</style>
